package org.dromara.web.controller;

import org.dromara.netbar.domain.vo.NetbarCouponVo;
import org.dromara.netbar.service.impl.CouponService;

import java.util.Calendar;

/**
 * @author ZhouWenTao
 * @create 2025-07-19 9:44
 */
public class test2 {
    public static boolean isCardValid(Long startTime, Long endTime, Long currentTime) {
        Calendar startCal = Calendar.getInstance();
        startCal.setTimeInMillis(startTime);
        int startHour = startCal.get(Calendar.HOUR_OF_DAY);

        Calendar endCal = Calendar.getInstance();
        endCal.setTimeInMillis(endTime);
        int endHour = endCal.get(Calendar.HOUR_OF_DAY);

        Calendar currentCal = Calendar.getInstance();
        currentCal.setTimeInMillis(currentTime);
        int currentHour = currentCal.get(Calendar.HOUR_OF_DAY);

        if (startHour < endHour) {
            // 当天包时 (比如 8点-12点)
            return currentHour >= startHour && currentHour < endHour;
        } else if (startHour > endHour) {
            // 包夜 (比如 22点-6点)
            return currentHour >= startHour || currentHour < endHour;
        } else {
            // 24小时包时
            return true;
        }
    }

    public static void main(String[] args) {
        // 测试包夜场景
        long startTime = 1753574461000L; // 2025-07-27 22:01:01
        long endTime = 1753574461000L + 8 * 3600 * 1000; // 第二天 6:01:01
        long currentTime = 1753574461000L + 2 * 3600 * 1000; // 2025-07-28 00:01:01

        System.out.println(isCardValid(startTime, endTime, currentTime)); // 应该返回true
    }


}
